package com.fr.web.core.service;

import com.fr.base.FRContext;
import com.fr.base.core.util.TemplateUtils;
import com.fr.web.Weblet;
import com.fr.web.core.SessionIDInfor;
import com.fr.web.core.WebUtils;
import java.util.Map;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class ReportletDealWith
{
  public static void dealWithReportlet(HttpServletRequest paramHttpServletRequest, HttpServletResponse paramHttpServletResponse, Weblet paramWeblet)
    throws Exception
  {
    String str1 = SessionDealWith.generateSessionID(paramHttpServletRequest, paramHttpServletResponse, paramWeblet);
    if ((str1 == null) || (!(SessionDealWith.hasSessionID(str1))))
      return;
    if (paramHttpServletRequest.getParameter("__isjmeter__") != null)
    {
      JMeterService.dealWithJMeter(str1, paramHttpServletRequest, paramHttpServletResponse);
    }
    else if (WebUtils.getHTTPRequestParameter(paramHttpServletRequest, "format") != null)
    {
      String str2 = WebUtils.getHTTPRequestParameter(paramHttpServletRequest, "format");
      if (str2.equals("pdfprint"))
      {
        PDFPrintService.dealWithPDFPrint(paramHttpServletRequest, paramHttpServletResponse);
      }
      else
      {
        String str3 = WebUtils.getHTTPRequestParameter(paramHttpServletRequest, "__embed__");
        boolean bool = "true".equals(str3);
        ExportService.dealWithExport(paramHttpServletRequest, paramHttpServletResponse, str1, bool);
      }
    }
    else
    {
      dealWithPageHtml(paramHttpServletRequest, paramHttpServletResponse, str1);
    }
  }

  private static void dealWithPageHtml(HttpServletRequest paramHttpServletRequest, HttpServletResponse paramHttpServletResponse, String paramString)
    throws Exception
  {
    SessionIDInfor localSessionIDInfor = SessionDealWith.getSessionIDInfor(paramString);
    if (localSessionIDInfor == null)
      return;
    String str = WebUtils.getHTTPRequestParameter(paramHttpServletRequest, "op");
    Map localMap = null;
    if ("edit".equals(str))
      localMap = WebUtils.context4EditTpl(paramHttpServletRequest, localSessionIDInfor);
    else
      localMap = WebUtils.context4PageTpl(paramHttpServletRequest, localSessionIDInfor);
    paramHttpServletResponse.setHeader("Pragma", "No-cache");
    paramHttpServletResponse.setHeader("Cache-Control", "no-cache, no-store");
    paramHttpServletResponse.setDateHeader("Expires", -10L);
    try
    {
      if ("edit".equals(str))
        TemplateUtils.dealWithTemplate("/com/fr/web/core/edit.html", paramHttpServletResponse, localMap);
      else if (paramHttpServletRequest.getParameter("__isdebug__") != null)
        TemplateUtils.dealWithTemplate("/com/fr/web/core/page_debug.html", paramHttpServletResponse, localMap);
      else if ("simplesheet".equals(str))
        SimpleSheetService.dealWithSimpleSheet(localSessionIDInfor, paramHttpServletRequest, paramHttpServletResponse, localMap);
      else
        TemplateUtils.dealWithTemplate("/com/fr/web/core/page.html", paramHttpServletResponse, localMap);
    }
    catch (Exception localException)
    {
      FRContext.getLogger().log(Level.WARNING, localException.getMessage(), localException);
    }
  }
}